#{extends 'sidebar.html' /}
<div id="all">
#{if emailing}<div class="frontTitle" id = "modify_emailing"><img src="/public/images/famfam/cross.png" /> <a onclick="modify_emailing(0);">Stop receiving Emails?</a></div>#{/if}
#{else}<div class="frontTitle" id = "modify_emailing"><img src="/public/images/famfam/accept.png" /> <a onclick="modify_emailing(1);">Enable receiving Emails?</a></div>#{/else}
#{if pageOfNotifications.size()==0}
<div id="notifications">#{note}Sorry you currently have no notifications#{/note}</div>
#{/if}#{else}
#{list items:pageOfNotifications, as:'noti'}
<div><p><font color="white"><b>${noti.actionPerformer.name}</b> has ${noti.actionType} ${noti.resourceType} #{if noti.actionType == 'Invited'}<a onclick="showProjectWorkspace(${noti.project.id})">${noti.resourceName}</a>#{/if}
#{elseif noti.actionType == 'assigned' }task <a onclick="showProjectWorkspace(${noti.project.id})">${noti.resourceName}</a> in the project <a onclick="showProjectWorkspace(${noti.project.id})">${noti.project.name}</a>#{/elseif}
#{elseif noti.actionType == 'invited'} <a onclick="showProjectWorkspace(${noti.project.id});loadBox('/meetings/viewmeetings?id=${noti.resourceURL}','workspace-${noti.project.id}','reload-meetings-${noti.project.id}')">${noti.resourceName}</a>#{/elseif}
#{elseif noti.actionType == 'edited' } <a onclick="showProjectWorkspace(${noti.project.id})">${noti.resourceName}</a> in the project <a onclick="showProjectWorkspace(${noti.project.id})">${noti.project.name}</a>#{/elseif}
#{elseif noti.actionType == 'deleteColumn'} ${noti.resourceName}#{/elseif}
#{elseif noti.project == null} ${noti.resourceName}#{/elseif}
#{else}
<a onclick="showProjectWorkspace(${noti.project.id})">${noti.resourceName}</a>
 #{/else} 
<!--  #{ifnot noti.project == null}
in project <a onclick="showProjectWorkspace(${noti.project.id})">${noti.project.name}</a>
#{/ifnot}--></p></font></div>
#{/list}
#{if !first}
<a onclick="$('#all').load('@{Application.showNotifications(page-1)}');" href"#" >Previous</a>
#{/if}
#{else}
<font color="grey">Previous</font>
#{/else}
#{if !last}
<a onclick="$('#all').load('@{Application.showNotifications(page+1)}');" href"#" >Next</a>
#{/if}
#{else}	
<font color="grey">Next</font>
#{/else}
#{/else}
<div class="p" style="display:none">
<a href="#"  style="display:inline-block" class="Notificationp" onclick="previousNotificationPage();"><span style="display:inline-block"class="ui-icon ui-icon-circle-arrow-w"></span></a>
<a href="#"  style="display:inline-block" class="Notificationn" onclick="nextNotificationPage();"><span style="display:inline-block"class="ui-icon ui-icon-circle-arrow-e"></span></a>
</div>
</div>
<script type="text/javascript">
function modify_emailing(i)
{
	var currentText = document.getElementById("modify_emailing").text;
	if(i==0)
		var res = confirm('Are you sure you want to stop receiving emails?');
	else
		var res = confirm('Are you sure you want to enable receiving emails?');
	if(res==true)
		$.post("@{Application.modifyEmailing}", {enable:i}, function(){
			if(i==0)				
				$('#modify_emailing').html('<img src="/public/images/famfam/accept.png" /> <a onclick="modify_emailing(1);">Enable receiving Emails?</a>');
			else
				$('#modify_emailing').html('<img src="/public/images/famfam/cross.png" /> <a onclick="modify_emailing(0);">Stop receiving Emails?</a>');
			});
}
	//search_notifications(0);
	function search_notifications(page) {
		$('#loading_img').show()
		$.post('/application/listNotifications', {page: page}, function(response){
			body = $('#notifications')
			body.empty()
			$('#loading_img').hide()
			$(response.logs).each(function() {
				body.append('<li id="log_'+this.id+'" class="log_item"><a onclick="show_log_content('+this.id+')">'+this.message+'</a><div></div></li>')
			})
			$('#notifications_pages').remove()
			body.after('<div id="notifications_pages" class="page_numbers _14">')
			div = $('#notifications_pages')
			if (response.currentPage != 1) {
				div.append('<a onclick="search_notifications('+(page-1)+')">Previous</a> ')
			}
			if (response.currentPage <= response.totalPages) div.append(response.currentPage + ' / ' + response.totalPages + ' ')
			if (response.currentPage != response.totalPages && response.totalPages) {
				div.append('<a onclick="search_notifications('+(page+1)+')">Next</a>')
			}
		})
	}
</script>